<template>
  <div>
    <el-table :data="manegelist" border style="width: 100%">
      <el-table-column prop="id" label="用户编号" width="180">
      </el-table-column>
      <el-table-column prop="username" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.status == 1">启用</el-button>
            <el-button type="warning" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="success" @click="bianji(scope.row.uid)">编辑</el-button>
            <v-del @del="del(scope.row.uid)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="manegecount"
      :page-size="manegesize"
      @current-change="change"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import { userdelete } from "../../../request/api";
import { successAlert, warningAlert } from "../../../util/alert";
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      reqmanegelist: "manege/reqchangelist",
      reqchangecount: "manege/reqchangecount",
      reqchangepage: "manege/reqchangepage",
    }),
    // 页数发送改变
    change(num) {
      // console.log(num);
      this.reqchangepage(num);
    },
    // 点击删除
    del(uid) {
      // console.log(uid);
      userdelete({ uid: uid }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          // 刷新列表
          this.reqmanegelist();
          // 刷新总个数
          this.reqchangecount()
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    // 点击编辑
    bianji(uid){
      this.$emit('bianji',uid)
    }
  },
  computed: {
    ...mapGetters({
      manegelist: "manege/list",
      manegecount: "manege/count",
      manegepage: "manege/page",
      manegesize: "manege/size",
    }),
  },
  mounted() {
    // 每一次进来都将状态层的当前页码数变成1
    this.reqchangepage(1);
    this.reqmanegelist();
    this.reqchangecount();
  },
};
</script>

<style lang="less" scoped>
</style>